home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1996 February / macformat-034.iso / mac / Shareware City / Developers / appe Windows 2.03 / notify.c < prev    next >
Encoding:
Text File  |  1995-06-14  |  2.2 KB  |  80 lines  |  [TEXT/CWIE]

  1. // File "notify.c" - 
  2.  
  3. #include "main.h"
  4. #include "notify.h"
  5.  
  6. // * ****************************************************************************** *
  7. // Global Declarations
  8.  
  9. extern GlobalsRec glob;
  10. Boolean gDoneFlag=FALSE;
  11. NMUPP gNMDoneUPP=0;
  12.  
  13. // * ****************************************************************************** *
  14. // * ****************************************************************************** *
  15.  
  16. void UserNotify(short notifyList, short notifyIndex, Boolean exit) {
  17.     long saveA5;
  18.     Ptr buffer;
  19.     NMRecPtr notify=0;
  20.     StringPtr nmStr=0;
  21.     EventRecord tempEvent;
  22.     
  23.     if (! gNMDoneUPP) gNMDoneUPP = NewNMProc(CompleteNotify);
  24.     if (! gNMDoneUPP) goto HANDLE_ERROR;
  25.     
  26.     // Allocate one buffer for all the notification info
  27.     buffer = NewPtrSysClear(sizeof(NMRec) + sizeof(Str255));
  28.     if (! buffer) goto HANDLE_ERROR;
  29.     notify = (NMRecPtr) buffer;
  30.     nmStr = (StringPtr) buffer + sizeof(NMRec);
  31.     
  32.     SetA5(saveA5 = SetA5(0));
  33.     GetIndString(nmStr, notifyList, notifyIndex);
  34.     if (! nmStr[0]) goto HANDLE_ERROR;
  35.     
  36.     notify->qLink = 0;
  37.     notify->qType = nmType;
  38.     notify->nmMark = 0;
  39.     notify->nmIcon = 0;
  40.     notify->nmSound = (Handle) -1;
  41.     notify->nmStr = nmStr;
  42.     notify->nmResp = gNMDoneUPP; 
  43.     notify->nmRefCon = saveA5;
  44.     NMInstall(notify);
  45.     
  46.     glob.modalFloats = TRUE;     // Block the floaters from displaying
  47.     gDoneFlag = FALSE;            // Prime the cleanup semaphore 
  48.     
  49.     if (! exit) return;
  50.     
  51.     // We need to surrender time to let the notification complete
  52.     //   before it is safe to release the notification and quit.
  53.     while(! gDoneFlag) WaitNextEvent(everyEvent, &tempEvent, 60, 0);
  54.     ExitToShell();    // Note: patched or not, E2S() should succeed
  55.  
  56.  
  57. HANDLE_ERROR:
  58.     if (notify) DisposePtr((Ptr) notify);
  59.  
  60.     SysBeep(7);
  61.     if (exit) ExitToShell();
  62.       else return;
  63.     }
  64.  
  65. // * ****************************************************************************** *
  66. // * ****************************************************************************** *
  67.  
  68. pascal void CompleteNotify(NMRecPtr notify) {
  69.     long saveA5 = SetA5(notify->nmRefCon);
  70.     
  71.     glob.modalFloats = FALSE;    // Now we can show the floaters!
  72.     gDoneFlag = TRUE;            // And, if necessary, reset the done flag
  73.     
  74.     NMRemove(notify);
  75.     DisposePtr((Ptr) notify); 
  76.     
  77.     SetA5(saveA5);
  78.     }
  79.         
  80.